<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>16vue-todo list.html</title>
    <script type="text/javascript" src="static/vue.min.js"></script>
    <script type="text/javascript" src="static/jquery-1.12.4.min.js"></script>
    <style type="text/css">
        .list_con {
            width: 600px;
            margin: 50px auto 0;
        }

        .inputtxt {
            width: 550px;
            height: 30px;
            border: 1px solid #ccc;
            padding: 0px;
            text-indent: 10px;
        }

        .inputbtn {
            width: 40px;
            height: 32px;
            padding: 0px;
            border: 1px solid #ccc;
        }

        .list {
            margin: 0;
            padding: 0;
            list-style: none;
            margin-top: 20px;
        }

        .list li {
            height: 40px;
            line-height: 40px;
            border-bottom: 1px solid #ccc;
        }

        .list li span {
            float: left;
        }

        .list li a {
            float: right;
            text-decoration: none;
            margin: 0 10px;
        }
    </style>
    <script>


    </script>
</head>
<body>

<div class="list_con">
    <h2>To do list</h2>
    <input type="text" name="" id="txt1" class="inputtxt" v-model="msg">
    <input type="button" name="" value="增加" id="btn1" class="inputbtn" @click="add()">

    <ul id="list" class="list">

        <li v-for="message,index in objList">
            <span>{{message}}</span>
            <a href="javascript:;" class="up" @click="moveUp(index)"> ↑ </a>
            <a href="javascript:;" class="down" @click="moveDown(index)"> ↓ </a>
            <a href="javascript:;" class="del" @click="del(index)">删除</a>
        </li>

    </ul>

</div>
<script>
    new Vue({
        el: ".list_con",
        data: {
            msg:"",
            objList: ["学习html", "学习css", "学习javascript"]
        },
        methods: {
            add: function () {
                // 点击添加按钮后，往数组中追加元素
                this.objList.push(this.msg);
                this.msg="";
                $(function () {
                    $("#txt1").focus();
                })
            },
            del:function (index) {
                this.objList.splice(index,1);
            },
            moveUp:function (index) {
                if (index==0){
                    confirm("亲已经到顶了！")
                    return;
                }
                this.objList.splice(index-1,0,this.objList[index]);
                this.objList.splice(index+1,1);
            },
            moveDown:function (index) {
                if (index==this.objList.length-1){
                    confirm("亲已经到底了！")
                    return;
                }
                this.objList.splice(index+2,0,this.objList[index]);
                this.objList.splice(index,1);
            }
        }
    });
</script>
</body>
</html>